package com.luo.stu;

/**
 * @author: luosiyu
 * @Description:
 * @Version: 1.0
 */

public class test_2 {
    public static void main(String[] age){

        //1：冒泡排序
        System.out.println("----------------第一题----------------");
        System.out.print("排序前：");
        int[] arr = new int[10];
        for (int i = 0;i<10;i++){
            arr[i]=(int)(100*Math.random());
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
        System.out.print("排序后：");
        sort(arr);
        for(int i = 0;i<10;i++){//遍历数组
            System.out.print(arr[i]+"\t");
        }

        System.out.println();
        System.out.println("--------------第二题---------------");
        Students[] students = new Students[]{
         new Students("100","Zhang",78,75,87),
         new Students("101","Liu",65,70,72),
         new Students("102","Li",90,76,75),
        };
        for(int i = 0;i<students.length;i++){
            students[i].disp();
            students[i].sum();
        }

        System.out.println();
        System.out.println("--------------第三题---------------");
        //用数组存放
        Student_2[] student2s =new Student_2[]{
                new Student_2("20170","abc",0),
                new Student_2("20171","abc",10),
                new Student_2("20172","abc",20),
                new Student_2("20173","abc",30),
                new Student_2("20174","abc",40),
                new Student_2("20175","abc",50),
                new Student_2("20176","abc",60),
                new Student_2("20177","abc",70),
                new Student_2("20178","abc",80),
                new Student_2("20179","abc",90),
        };
        for(int i = 0;i<student2s.length;i++){
            student2s[i].Disp();
        }


    }
    public static void sort(int[] arr){
        int temp = 0;
        boolean flag = false;
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = 0; i < arr.length-1 -j ; i++) {
                if (arr[i] > arr[i+1]){
                    temp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = temp;
                    flag = true;
                }
            }
            if (flag){
                flag = false;
            }else {
                break;
            }
        }

    }
}
